package com.study.lihan;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

import java.util.Vector;

@Slf4j(topic = "c.TestMultiReBaised")
public class TestMultiReBaised {
    public static void main(String[] args) {
        Vector<Dog> list = new Vector<>();


       Thread t1 = new Thread(()->{
           for (int i = 0; i < 30 ; i++) {
               Dog  dog = new Dog();
               list.add(dog);
               synchronized (dog){
                   log.info(i+ "\t" + ClassLayout.parseInstance(dog).toPrintable());
               }

           }
           synchronized (list){
               log.info("线程1");
               list.notify();
           }
       },"t1");
       t1.start();


        Thread t2 = new Thread(()->{
            synchronized (list){
                try {
                    log.info("线程2");
                    list.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.info("=========================");
            for (int i = 0; i < 30 ; i++) {
                Dog  dog = list.get(i);
                list.add(dog);
                log.info(i+ "\t" + ClassLayout.parseInstance(dog).toPrintable());
                synchronized (dog){
                    log.info(i+ "\t" + ClassLayout.parseInstance(dog).toPrintable());
                }
                log.info(i+ "\t" + ClassLayout.parseInstance(dog).toPrintable());

            }
        },"t2");
        t2.start();


    }
}
